﻿using Manager.Service;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Manager.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class MqttController : ControllerBase
    {
        private readonly MqttService _mqttService;

        public MqttController(MqttService mqttService)
        {
            _mqttService = mqttService;
        }

        [HttpPost("publish")]
        public async Task<ObjectResult> PublishMessage([FromQuery] string topic, [FromBody] string message)
        {
            if (string.IsNullOrEmpty(topic) || string.IsNullOrEmpty(message))
            {
                return new ObjectResult("Topic and message cannot be empty.");
            }
            await _mqttService.PublishLargeMessageAsync(topic, message);
            return new ObjectResult("消息发送成功");
        }
    }
}
